package com.wangyi.fightimg.base;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author wagnYi
 *         Fragment基类
 */

public abstract class BaseFragment extends Fragment {
    protected View rootView;
    protected Context context;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(addLayout(), null);
            context = getActivity();
            findView();
            addListener();
            initializedPage();
        }
        return rootView;
    }


    public void requestPermission(String permission, int requestCode,Runnable runnable) {
        if (Build.VERSION.SDK_INT >= 23) {
            if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{permission}, requestCode);
            }
        }
    }

    protected abstract int addLayout();

    protected abstract void findView();

    protected abstract void addListener();

    protected abstract void initializedPage();
}
